package com.ys.controller.api.mail;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.entity.mail.MailTag;
import com.ys.service.mail.MailTagService;
import com.ys.service.sys.CommonApiService;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/mailTag")
public class ApiInterMailTagController {
	
	@Autowired
	private CommonApiService<MailTag> commonApiService;
	@Autowired
	private MailTagService mailTagService;

	@RequiresPermissions("mailTag:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(@ModelAttribute MailTag cond){
		
		cond.addLeftJoin("TS_UserChange B ON B.Id = A.CreateChangeId")
		.addField("B.UserId createUserId");
		
		return commonApiService.searchLay(cond);
	}

	@RequiresPermissions("mailTag:view")
	@RequestMapping("/searchForModal")
    @ResponseBody
	public LayuiTableVoJA searchForModal(@ModelAttribute MailTag cond){
		
		cond.addLeftJoin("TS_UserChange B ON B.Id = A.CreateChangeId")
		.where("B.UserId = '" + ShiroUtils.getUserId() + "'");
		
		return commonApiService.searchLay(cond);
	}
	
	/**
	 * 新增
	 */
	@PostMapping("/add")
    @ResponseBody
	public R add(Model model, HttpServletRequest request, HttpServletResponse response,
			String name){
		
		return mailTagService.add(name);
	}
	
	/**
	 * 编辑
	 */
	@PostMapping("/edit")
    @ResponseBody
	public R edit(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id,
			String name){
		
		return mailTagService.edit(id, name);
	}
}
